<?php defined('IN_IA') or exit('Access Denied');?><?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/header', TEMPLATE_INCLUDEPATH)) : (include template('common/header', TEMPLATE_INCLUDEPATH));?>
<?php  load()->func('tpl')?>
<ul class="nav nav-tabs">
	<li><a href="javascript:history.go(-1);">返回</a></li>
	<li <?php  if($operation == 'post') { ?>class="active"<?php  } ?>><a href="<?php  echo $this->createWebUrl('themeset', array('op' => 'post'));?>">添加主题</a></li>
	<li <?php  if($operation == 'display') { ?>class="active"<?php  } ?>><a href="<?php  echo $this->createWebUrl('themeset', array('op' => 'display'));?>">管理主题</a></li>
</ul>
<link href="../addons/wmb_goshare/template/css/lhgcalendar.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../addons/wmb_goshare/template/js/lhgcore.min.js"></script>
<script type="text/javascript" src="../addons/wmb_goshare/template/js/lhgcalendar.min.js"></script>

<style>
.theme_list{overflow:hidden; padding-top:15px;}
.theme_list li{border:1px #DDD solid; width:320px; float:left; margin-left:15px; margin-bottom:10px;}
.theme_list li .theme_pic{display:block; width:320px; height:160px; overflow:hidden;}
.theme_list li .theme_pic img{width:320px;}
.theme_list li .theme_main{padding:10px; overflow:hidden;}
.theme_list li .theme_main .theme_title{font-size:16px; height:20px; width:217px; overflow:hidden;}
.theme_list li .theme_main .pull-left{color:#999;}
</style>
<?php  if($operation == 'post') { ?>
<div class="main">
	<form action="" method="post" onsubmit="return check(this)" class="form-horizontal form" enctype="multipart/form-data">
		<input type="hidden" name="themeid" value="<?php  echo $theme['id'];?>" />
<div class="panel panel-default">
    <div class="panel-heading">
        主题编辑
    </div>
    <div class="panel-body">
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 活动主题名称</label>
            <div class="col-sm-9 col-xs-12">
               	<input type="text" name="themename" class="form-control" value="<?php  echo $theme['themename'];?>" placeholder="活动主题名称" />
				<div class="help-block"></div>
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 网页标题</label>
            <div class="col-sm-9 col-xs-12">
               	<input type="text" name="headtitle" class="form-control" value="<?php  echo $theme['headtitle'];?>" placeholder="网页标题内容" />
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 主题名称</label>
            <div class="col-sm-9 col-xs-12">
               <textarea style="height:100px; width:600px;" class="span7 jq_watermark" name="themetitle" cols="70" placeholder="活动的主题"><?php  echo $theme['themetitle'];?></textarea>
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 逾期主题名称</label>
            <div class="col-sm-9 col-xs-12">
			  <textarea style="height:100px; width:600px;" class="span7 jq_watermark" name="overtitle" cols="70" placeholder="活动已经结束啦，下次早点来哟"><?php  echo $theme['overtitle'];?></textarea>
            </div>
        </div>
 		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 主题图片</label>
            <div class="col-sm-9 col-xs-12">
               	<?php  echo tpl_form_field_image('themelogo', $theme['themelogo']);?>
				<div class="help-block">*建议图片像素：640*500</div>
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 主办方名称</label>
            <div class="col-sm-9 col-xs-12">
               	<input type="text" name="undertaker" class="form-control" value="<?php  echo $theme['undertaker'];?>" placeholder="主办方名称" />
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 起始日期</label>
            <div class="col-sm-9 col-xs-12">
               	<input type="text" id="cal1" name="begintime" class="form-control" value="<?php  echo $theme['begintime'];?>" />
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 截止日期</label>
            <div class="col-sm-9 col-xs-12">
               	<input type="text" id="cal2" name="endtime" class="form-control" value="<?php  echo $theme['endtime'];?>" />
            </div>
        </div>
<script type="text/javascript">
J(function(){
	J('#cal1').calendar({ format:'yyyy-MM-dd' });
	J('#cal2').calendar({ format:'yyyy-MM-dd' });
});
</script>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 奖品组设置</label>
            <div class="col-sm-9 col-xs-12">
               	<select name="groupid" id="groupid"
					class="form-control" style="float: left">
					<?php  if(is_array($groups)) { foreach($groups as $group) { ?>
						<option value="<?php  echo $group['id'];?>" <?php  if($group['id'] == $theme['groupid']) { ?> selected = "selected" <?php  } ?> ><?php  echo $group['groupname'];?></option>
				    <?php  } } ?>
				</select> 
				<script>
					if ("{$theme['groupname']" != "") {
						$("#groupid").value = "<?php  echo $theme['groupname'];?>";
					}
				</script>
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 兑奖地址</label>
            <div class="col-sm-9 col-xs-12">
               <input type="text" name="place" class="form-control" value="<?php  echo $theme['place'];?>" placeholder="兑奖地址" />
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 兑奖电话</label>
            <div class="col-sm-9 col-xs-12">
               	<input type="text" id="tel" name="tel" class="form-control" value="<?php  echo $theme['tel'];?>" placeholder="兑奖电话" />
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告一区标题</label>
            <div class="col-sm-9 col-xs-12">
               	<input type="text" name="ad1" class="form-control" value="<?php  echo $theme['ad1'];?>" placeholder="标题" />
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告一区内容</label>
            <div class="col-sm-9 col-xs-12">
               	<textarea id='share_txt' style="height:200px; width:600px;" class="span7 jq_watermark" name="ad1content" cols="70" placeholder="广告内容"><?php  echo $theme['ad1content'];?></textarea>
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告二区标题</label>
            <div class="col-sm-9 col-xs-12">
               <input type="text" name="ad2" class="form-control" value="<?php  echo $theme['ad2'];?>" placeholder="标题" />
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告二区内容</label>
            <div class="col-sm-9 col-xs-12">
               	<textarea  id='share_txta' style="height:200px; width:600px;" class="span7 jq_watermark" name="ad2content" cols="70" placeholder="广告内容"><?php  echo $theme['ad2content'];?></textarea>
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告三区标题</label>
            <div class="col-sm-9 col-xs-12">
               	<input type="text" name="ad3" class="form-control" value="<?php  echo $theme['ad3'];?>" placeholder="标题" />
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告三区内容</label>
            <div class="col-sm-9 col-xs-12">
               	<textarea id='share_txtb' style="height:200px; width:600px;" class="span7 jq_watermark" name="ad3content" cols="70" placeholder="广告内容"><?php  echo $theme['ad3content'];?></textarea>
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告三区图片</label>
            <div class="col-sm-9 col-xs-12">
               	<?php  echo tpl_form_field_image('ad3pic', $theme['ad3pic']);?>
				<div class="help-block">*建议图片像素：640*900</div>
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 页面底部横幅图片</label>
            <div class="col-sm-9 col-xs-12">
               	<?php  echo tpl_form_field_image('footpic', $theme['footpic']);?>
				<div class="help-block">*建议图片像素：300*30</div>
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 底部图片链接地址</label>
            <div class="col-sm-9 col-xs-12">
               	<input type="text" name="url" class="form-control" value="<?php  echo $theme['url'];?>" placeholder="http://" />
            </div>
        </div>
		<div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 分享图标</label>
            <div class="col-sm-9 col-xs-12">
               	<?php  echo tpl_form_field_image('sharepic', $theme['sharepic']);?>
				<div class="help-block">*建议图片像素：100*100</div>
            </div>
        </div>

			
    </div>
</div>
   <div class="form-group">
			<div class="col-sm-12">
				<input name="submit" type="submit" value="提交" class="btn btn-primary col-lg-1" />
				<input type="hidden" name="token" value="<?php  echo $_W['token'];?>" />
			</div>
   </div>	
		

	</form>
</div>
<script charset="utf-8" src="./resource/script/kindeditor-4.1.10/kindeditor.js"></script>
<script charset="utf-8" src="./resource/script/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script type="text/javascript">
        KindEditor.ready(function(K) {
                window.editor = K.create('#share_txt');
				window.editor = K.create('#share_txta');
				window.editor = K.create('#share_txtb');
        });
    
</script>
 
<script type="text/javascript">
	function check(form) {

		if (!form['themename'].value) {
			$("input[name='themename']").focus();
			alert('主人，请输入活动的主题名称');
			return false;
		}
		if (!form['headtitle'].value) {
			$("input[name='headtitle']").focus();
			alert('主人，请输入网页标题');
			return false;
		}		
		if (!form['themetitle'].value) {
			$("input[name='themetitle']").focus();
			alert('主人，请输入活动的主题内容');
			return false;
		}
		if (!form['undertaker'].value) {
			$("input[name='undertaker']").focus();
			alert('主人，请输入主办方名称');
			return false;
		}	
		
		if (!form['begintime'].value) {
			$("input[name='begintime']").focus();
			alert('主人，请点击选择活动的开始日期');
			return false;
		}
		if (!form['endtime'].value) {
			$("input[name='endtime']").focus();
			alert('主人，请点击选择活动的截止日期');
			return false;
		}
		
		var str1 = $('#cal1').val();
		var str2 = $('#cal2').val();
		var d1 = new Date(str1); 
		var d2 = new Date(str2); 
		if(Date.parse(d1) - Date.parse(d2) >= 0){   
			$("input[name='endtime']").focus();
			alert('主人，截止日期要比开始日期晚一些日子'); 
			return false;
		} 
		
		if (!form['place'].value) {
			$("input[name='place']").focus();
			alert('主人，请输入兑奖地址');
			return false;
		}
		if (!form['tel'].value) {
			$("input[name='tel']").focus();
			alert('主人，请输入兑奖电话');
			return false;
		}else{
			 var tel = $('#tel').val();
		     if (tel.search(/^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}$/) == -1) {
		    		$("input[name='tel']").focus();
					//alert('主人，请输入正确的手机号码');
					return true;
				}
		}	
		
		if ((!form['ad1'].value && form['ad1content'].value.length > 0) || (form['ad1'].value && form['ad1content'].value.length <= 0)) {
			$("input[name='ad1']").focus();
			alert('请输入广告一区的标题和内容');
			return false;
		}
		if ((!form['ad2'].value && form['ad2content'].value.length > 0) || (form['ad2'].value && form['ad2content'].value.length <= 0)) {
			$("input[name='ad2']").focus();
			alert('请输入广告二区的标题和内容');
			return false;
		}
		if ((!form['ad3'].value && form['ad3content'].value.length > 0) || (form['ad3'].value && form['ad3content'].value.length <= 0)) {
			$("input[name='ad3']").focus();
			alert('请输入广告三区的标题和内容');
			return false;
		}
		return true;
	}
</script>
 
<?php  } else if($operation == 'display') { ?>
<ul class="unstyled theme_list">
	<?php  if(is_array($list)) { foreach($list as $item) { ?>
	<li>
		<a href="<?php  echo $this->CreateWebUrl('themeset', array('themeid' => $item['id'], 'op' => 'post'))?>" class="theme_pic"><?php  if($item['themelogo']) { ?><img src="<?php  echo $_W['attachurl'];?><?php  echo $item['themelogo'];?>" width="180" /><?php  } else { ?><img src="<?php  echo $_W['siteroot'].$this->geturl(1);?>" width="180" /><?php  } ?></a>
		<div class="theme_main">
			<p>
				<span class="pull-left"><?php  echo $item['themename'];?></span><span class="pull-right"><a href="<?php  echo $this->CreateWebUrl('themeset', array('themeid' => $item['id'], 'op' => 'post'))?>">编辑</a> 
				<a href="<?php  echo $this->CreateWebUrl('themeset', array('themeid' => $item['id'], 'op' => 'delete'))?>" onclick="return confirm('此操作将删除主题和对应的兑奖记录，确定删除码？'); return false;">删除</a></span>
			</p>
		</div>
	</li>
	<?php  } } ?>
</ul> 
<?php  } ?>
<?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/footer', TEMPLATE_INCLUDEPATH)) : (include template('common/footer', TEMPLATE_INCLUDEPATH));?>
